﻿using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace BlazorLearn.Shared.Components;
public class Badge : ComponentBase
{
    //<Badge>徽章</Badge>

    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public string? Color { get; set; } = "primary";

    [Parameter] public bool Link { get; set; }

    protected override void BuildRenderTree(RenderTreeBuilder builder)
    {
        builder.OpenElement(100, Link ? "a" : "span");

        builder.AddAttribute(101, "class", $"badge bg-{Color}");
        builder.AddAttribute(102, "onclick", EventCallback.Factory.Create<ChangeEventArgs>(this, (e) =>
        {
            Console.Write("点击了一下");
        }));
        builder.AddContent(102, ChildContent);

        builder.CloseElement();


        builder.OpenComponent<Button>(0);
        builder.AddAttribute(1, nameof(Button.ChildContent),
            (RenderFragment)(builder => builder.AddContent(0, "按钮")));
        builder.CloseComponent();
    }
}
